<?php

namespace App\Services;

use App\Models\Article;

class ArticleService extends BaseService
{
    /**
     * 获取列表
     * @return
     */
    public function list($page,$limit,$sort,$order, $article_categories_id,$title,$recommend,$top,$status) {
        $query = Article::query();
        if(isset($article_categories_id)){
            $query->where('article_categories_id',$article_categories_id);
        }
        if(!empty($title)){
            $query->where('title','like',"%$title%");
        }
        if(isset($recommend)){
            $query->where('recommend',$recommend);
        }
        if(isset($top)){
            $query->where('top',$top);
        }
        if(isset($status)){
            $query->where('status',$status);
        }

        return $query->orderBy($sort,$order)->paginate($limit, ['*'], 'page', $page);
    }
    /**
     * 获取所有
     * @return
     */
    public function listAll($name,$top,$recommend,$status,$article_categories_id,$sort,$order) {
        $query = Article::query();
        if(!empty($name)){
            $query->where('name','like',"%$name%");
        }
        if(isset($article_categories_id)){
            $query->where('article_categories_id',$article_categories_id);
        }
        if(isset($top)){
            $query->where('top',$top);
        }
        if(isset($recommend)){
            $query->where('recommend',$recommend);
        }
        if(isset($status)){
            $query->where('status',$status);
        }

        return $query->orderBy($sort,$order)->get();
    }
}
